/*
 * Copyright 1990-2008, Mark Little, University of Newcastle upon Tyne
 * and others contributors as indicated 
 * by the @authors tag. All rights reserved. 
 * See the copyright.txt in the distribution for a
 * full listing of individual contributors. 
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License, v. 2.1.
 * This program is distributed in the hope that it will be useful, but WITHOUT A 
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License,
 * v.2.1 along with this distribution; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 * 
 * (C) 1990-2008,
 */
 /*
 * Copyright (C) 1994-1998,
 *
 * Department of Computing Science,
 * The University,
 * Newcastle upon Tyne,
 * UK.
 *
 * $Id: Process.n,v 1.10 1998/08/28 14:19:51 nmcl Exp $
 */

#if defined(NO_INLINES) && !defined(PROCESS_CC_)

#else

#ifndef NO_INLINES
#  define INLINEF inline
#else
#  define INLINEF
#endif

INLINEF Boolean Scheduler::simulationStarted ()
{
    return Scheduler::schedulerRunning;
}

INLINEF void Scheduler::Suspend ()
{
    Scheduler::schedulerRunning = FALSE;
}

INLINEF void Scheduler::Resume ()
{
    Scheduler::schedulerRunning = TRUE;
}

INLINEF Scheduler& Scheduler::scheduler ()
{
    if (Scheduler::theScheduler == (Scheduler*) 0)
        Scheduler::theScheduler = new Scheduler;

    return *Scheduler::theScheduler;
}

INLINEF void Scheduler::terminate ()
{
    if (!Scheduler::theScheduler)
	return;
    
    theScheduler->Suspend();
    delete Scheduler::theScheduler;

    Scheduler::theScheduler = (Scheduler*) 0;
}

INLINEF double Process::evtime () const
{
    return wakeuptime;
}

INLINEF Boolean Process::terminated () const
{
    return Terminated;
}

INLINEF Boolean Process::passivated () const
{
    return Passivated;
}

INLINEF double Process::Time () const
{
    return Process::CurrentTime();
}

INLINEF Boolean Process::checkTime (double time) const
{
    return (Boolean) ((time >= 0) ? TRUE : FALSE);
}

INLINEF const Process* Process::current ()
{
    return (const Process*) Process::Current;
}

/*
 * A process is idle if it is not running *or* is not scheduled
 * on the event queue.
 */

INLINEF Boolean Process::idle () const
{
    return ((wakeuptime >= CurrentTime()) ? FALSE : TRUE);
}

// suspend current process indefinitely (i.e., make idle)

INLINEF void Process::Passivate ()
{
    if (!Passivated && (this == Process::Current))
        Cancel();
}

#ifdef INLINEF
#  undef INLINEF
#endif

#endif
